/**
 * 
 */
package com.google.code.sip.ucenter.dao.mongo;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.google.code.sip.core.dao.Page;
import com.google.code.sip.core.dao.mongo.GenericMongoDao;
import com.google.code.sip.ucenter.dao.UserDao;
import com.google.code.sip.ucenter.model.Role;
import com.google.code.sip.ucenter.model.User;

/**
 * @author Liuye
 * 
 */
public class UserDaoImpl extends GenericMongoDao<User, String> implements
		UserDao {
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.UserDao#getByName(java.lang.String)
	 */
	public User getByName(String username) {
		return getByProperty("username", username);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.UserDao#getByEmail(java.lang.String)
	 */
	public User getByEmail(String email) {
		return getByProperty("email", email);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.UserDao#getByHuoshowId(java.lang.String
	 * )
	 */
	public User getByHuoshowId(String huoshowId) {
		return getByProperty("huoshowId", huoshowId);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.code.sip.ucenter.dao.mongo.UserDao#getUser(java.lang.String,
	 * java.lang.String, java.lang.String)
	 */
	public User getUser(String username, String email, String huoshowId) {
		Map<String, Object> filters = new LinkedHashMap<String, Object>();
		if (StringUtils.isNotEmpty(username)) {
			filters.put("username", username);
		}
		if (StringUtils.isNotEmpty(email)) {
			filters.put("email", email);
		}
		if (StringUtils.isNotEmpty(huoshowId)) {
			filters.put("huoshowId", huoshowId);
		}
		return getByProperties(filters);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.UserDao#findByRole(com.google.code.
	 * ucenter.model.Role, com.google.code.sip.core.dao.Page)
	 */
	public Object findByRole(Role adminRole, Page<User> page) {
		return null;
	}

}
